package com.neu.controller;

import com.neu.constant.ResultCodeEnum;
import com.neu.mapper.ArticleMapper;
import com.neu.pojo.Article;
import com.neu.service.ArticleService;
import com.neu.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping(value = "/article", produces = {"application/json;charset=UTF-8"})
public class ArticleController {
    @Resource
    private ArticleMapper articleMapper;

    @Resource
    private ArticleService articleService;

    @GetMapping("/r")
    public Object read(@RequestParam("id") int id) {
        log.info("查询文档:{}", id);
        if (id <= 0) {
            return Result.error(ResultCodeEnum.PARAM_CHECK_ERROR);
        }
        return articleService.queryArticleInfo(id);
    }

    @PostMapping("/w")
    public Object write(@RequestBody Article article){
        log.info("修改文档...");
        return articleMapper.updateArticle(article);
    }
}
